package two_point

import C "gitee.com/ljfirst/algo-go-sdk/common/constant"

/**
 * @author ljfirst
 * @version V1.0
 * @date 2023/7/27 15:49
 * @author-Email ljfirst@mail.ustc.edu.cn
 * @blogURL https://blog.csdn.net/ljfirst
 * @description
 **/
type TwoSumByMap struct {
}

func (m *TwoSumByMap) Method(array []int, target int) []int {
	if len(array) == 0 {
		return nil
	}
	sumMap := make(map[int]bool, 0)
	for _, v := range array {
		_, exist := sumMap[target-v]
		if exist {
			return []int{target - v, v}
		} else {
			sumMap[v] = true
		}
	}
	return nil
}

func (m *TwoSumByMap) GetAttribute() *C.Attribute {
	return &C.Attribute{
		Tags: []string{},
		Desc: &C.Desc{
			Name:        "TwoSumByMap",
			NameCn:      "两数之和",
			Description: "",
			ParamsDesc: map[string]string{
			},
			Example: map[int]string{
			},
		},
	}
}
